<template>
<div class="common-seach-wrap">
    <!--秒杀活动-->
    <Active v-if="activeName == 'active'"></Active>
    <!--基础设置-->
    <Setting v-if="activeName == 'setting'"></Setting>
    <!-- 活动审核 -->
    <Audit v-if="activeName == 'audit'"></Audit>
  </div>
</template>

<script>
import { reactive, toRefs, defineComponent } from "vue";
import { useUserStore } from "@/store";
import Active from "./active/index.vue";
import Setting from "./setting/getSetting.vue";
import Audit from "./product/index.vue";
export default defineComponent({
  components: {
    Active,
    Setting,
    Audit
  },
  setup() {
    const {
      bus_emit,
      bus_off,
      bus_on
    } = useUserStore();
    const state = reactive({
      bus_emit,
      bus_off,
      bus_on,
      formInline: {
        nick_name: ""
      },
      /*参数*/
      param: {},
      /*当前选中*/
      activeName: "active",
      /*切换数组*/
      sourceList: [{
        key: "active",
        value: $t("plus.seckill_activity"),
        path: "/plus/seckill/active/index"
      }, {
        key: "setting",
        value: $t("plus.basic_setting"),
        path: "/plus/seckill/setting/getSetting"
      }, {
        key: "audit",
        value: $t("plus.activity_review"),
        path: "/plus/seckill/product/index"
      }],
      /*权限筛选后的数据*/
      tabList: [],
      /*判断third是否有参数*/
      is_third_param: false
    });
    return {
      ...toRefs(state)
    };
  },
  created() {
    this.tabList = this.authFilter();
    if (this.tabList.length > 0) {
      this.activeName = this.tabList[0].key;
    }
    if (this.$route.query.type != null) {
      this.activeName = this.$route.query.type;
    }

    /*监听传插件的值*/
    this.bus_on("activeValue", res => {
      this.activeName = res;
    });

    //发送类别切换
    let params = {
      active: this.activeName,
      list: this.tabList,
      tab_type: "seckill"
    };
    this.bus_emit("tabData", params);
  },
  beforeUnmount() {
    //发送类别切换
    this.bus_emit("tabData", {
      active: null,
      tab_type: "points",
      list: []
    });
    this.bus_off("activeValue");
  },
  methods: {
    /*权限过滤*/
    authFilter() {
      let list = [];
      for (let i = 0; i < this.sourceList.length; i++) {
        let item = this.sourceList[i];
        if (this.$filter.isAuth(item.path)) {
          list.push(item);
        }
      }
      return list;
    }
  }
});
</script>

<style scoped>
.operation-wrap {
  height: 124px;
  border-radius: 8px;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  padding: 30px 30px;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
  overflow: hidden;
  background: #909399;
  background-size: 100% 100%;
  color: #fff;
}
</style>

